package cn.duxiaod.demo.producerconsumer.b;

import java.util.concurrent.LinkedBlockingQueue;

/**
 * 生产者消费者模式：使用{@link java.util.concurrent.BlockingQueue}实现
 */
public class ProducerConsumerByBQTest {
    private static final Integer CAPACTITY = 5;
    public static void main(String[] args) {
        LinkedBlockingQueue<Integer> blockingQueue = new LinkedBlockingQueue<>(CAPACTITY);
        ProducerBQ p1 = new ProducerBQ("P-1", blockingQueue);
        ProducerBQ p2 = new ProducerBQ("P-2", blockingQueue);

        ConsumerBQ c1 = new ConsumerBQ("C-1", blockingQueue);
        ConsumerBQ c2 = new ConsumerBQ("C-2", blockingQueue);
        ConsumerBQ c3 = new ConsumerBQ("C-3", blockingQueue);
        p1.start();
        p2.start();

        c1.start();
        c2.start();
        c3.start();
    }
}
